Fixed a bug when trying to run the script via cron.