Improved daemon code