Slight improvement in isprime function