Refactor into gem