calcSpeed function created