Improve daemon code