Adding better error checking for invalid dates.