Refactored RemainingDuration into two separate functions and added error-handling.