Refactored. Added validation for dates