adding an extra check for pid-file creation, and making the output more reliable, especially when daemonizing