Removing some duplicated code and making the times react to the dates