Better date functions and a cleanup