Fixed bugs: datepicker now closes correctly in all states