Code generation update

Add most of code generation
Add some more error states
Fix some variable reporting