fixed a bug, introducing another memory bug