Fixed some issues, mainly when running in cron.