memory managment fixes