Daemon code review/merge request

Fixes for the #1 and #2 issues raised and code review request.

Please do code review and merge the changes to master if the fix is ok.