Factor learning switch out of controller into library.