fixed memory leaks introduced by returning a copy of existing value