memory leakage still present. Implemented NIO to file writing