Move all the import statements to the start of each module to eliminate duplicated code.
Fix bug when the time series covers a single month only (i.e. it does not straddle a month boundary).
Remove old useless functions.