First attempt at refactoring into a plugin