Correctly close open pipes after use

[Issue #310]