Some refactoring for extension code.