Factoring with common terms