Restructured factor deduction and fixed some related bugs with partials