Various fixes, removing of old and unnecessary code.

Will comment on some of the changes.
This was using state as a cache. state() is for things that should be persisted indefinetly, like last cron run time.