Refactor to fix mixing functions and kernels (issue #5).