More codegen refactors.. Added specs for casting a nilable type to nil and to a reference type