Generic factorization refactor.