refactored function to test if an integer is prime