Changed the way day is calculated to be more resilient
merging