refactor computing average speed