more correct memory managment