This is a better approach as initially thought in #191. What is missing is outlined in the (several) TODOs.