fixed datepicker and fixed up ugly code