rebuilt some date management logic