Make starting/stopping daemon more robust