Tweaked primeDecomposition function.