Cleaned up code for datepicker