modified/replaced prime-factor code