Refactored prime factors method