fixed date bug and refactored