More codegen refactors, and added a couple of specs