Timeperiod fixes and various other junk

Quite a lot of changes. A second set of eyes on the code would be awesome.