added tests, fixed pipe close bug