More well organized code

Created separate functions for datepicker control