fixed memory bug, finally