Made into daemon, increased error checking and various other changes