some memory optimization code changes