Refactored some code and added foreground function to daemon control class.