Fix loop, fix daemonize

ignore the first 4 changesets, they are duplicate to my last pull request. no conflicts though.

if you pull/merge the other pull request first, it should work. or just reject the other pull request, should work also.