Performance refactor https://github.com/KanoComputing/peldins/issues/949