refactored prime? method