Replaced hard coded time checks with function