Added time calculations function