fixed date calculation logic.  still needs cleanup