Refactor Kappa-specific functionality into separate classes and add subs for pre/post conditions.