Fixed bugs in date handling