Defined function for time of flight