Added better error handling for times