Refactored pipe and close error checking.