Updating generatePrime method