latest date logic fixed