Refactored prime builder.