1) Give all riders a body worn transponder, of the kind used in motor racing to trigger lap times.
2) The race result to be determined by the total time which each rider takes to complete all the stages. No bonus seconds awarded, no giving a whole bunch of riders the same finish time when the one at the front of the group clearly finished several seconds before the one at the back of the group.
You can still have a points based king of the mountain and a points based sprint competition, but the yellow jersey to go to the rider who completes all the race stages in the lowest aggregate time, with no "adjustments" i.e. time bonuses.