Fixed bug in date calculations

Fixed an error when calculating date differences
Various other changes