Cleaning up the date detection code