some memory profiling and optimization