dirty sigpipe & refactor