This MR closes #146 (closed).
It implements the solution based on this suggestion. Thank you, @simonspa.