proper_divisors() replaced by divisors(), for simplicity and generality.
Add some sanity checks to primefactors()