Refactored code; added tests of Daemon class