Script improved to be run by a cron task.