cleaned up problem 3. Corrected issue with recursion and duplicate factors.