ROFL. Thanks for the answer. I ended up rewriting the whole function so that it wasn't recursive. I kept refactoring farther than necessary due to a problem with the if statement controlling my recursion. :roll:

Basically the first problem was how to stop non-prime factors from appearing in the results, so I tried it recursively. Now what I do is use a boolean check to ensure the resulting array consists of completely prime numbers and simply re-process the non-primes each pass. It's pretty quick. But since I'm doing manipulation to the array I can't really pop/push them except for appending values (or at least in safety).

But hey, it now works in a pretty efficient manner and gives accurate results.

(Nevermind the delete bit now. )