Made prime checking slightly more efficient