Fixed bug. ready to test for cronjob.