calculate_time refactored again