refactored main Daemon loop to clean it up a bit.