SIGPIPE handler and minor bug fix