close and fix pipe in main