Finished first pass at code generation
fixed segfault on osx
Fixed a memory leak