Fixed memory bug in compiler, and made it more safe