Issue #3340482 by svendecabooter: clean up code according to Drupal standards + better error catching on cron