Refactor out penalty for scalar minimizers

Simple change, it is also quite nice to have the penatly function available to the outside. Makes it easier to use external minimizers.