Refactored code from app controller code back into gem.