Fixing cron issue and improving code redability