Fixed bugs found in further testing.

The cron-job was not thoroughly tested before but has been now.