Refactor code generation for global expressions