Removed logic from controller and placed into factory