added average speed, but code is untested!!!!