working version
remove debug output
remove bug with pipe closing