Fix bugs in the parent and child daemon code