Refactoring: avoid slow function definitions