cleaned up main function, fixed daemonization, and changed the debug messages to only when DEBUG is defined.