Fix for some memory related issues