Compiler code refactoring for goals compiled at runtime