Rewrite prime checker