Refactor jday

Refactor jday, plus some other small tidyups.