added fixes for memory usage