some memory management improvements