change valid_date function