Fixed some of the code up and added a cronjob