Fix memory problems with correct refs