Refactor code generator helper methods