datetime handling improved