Make daemonize script more robust