Refactor date logic