Fixes bug in datepicker.
Some code enhancements