Added null check for the case where the dates are not in the right order