Improve speed of IsPrime