refactored with Prime class