changed the checkprimes function to avoid more checks and assignments