Fix setting dates. Code clean up