Added some checks in.  Changed the isPrime to a standard for loop as it was causing some wierd iterator issues.