Fixed memory leak and cleaned up some pointer code. Emulation does not work currently