More code generation, optimizations, and bug fix. Much smaller now.