solved pipe problem and memory management