Code cleanup in progress

I found a bug when testing the scheduler. In my situation the htmlfiles aren’t generated anymore because of the scheduler.

I have fixed this in my version I’m running locally at the moment.

In this version a lot of code has been moved aroun to make the code a lot more tidy.