refactored, added the EndOfDay logic