added memory info and some memory optimizations