Major rework for #46