Manually restored PR #148 from @jmirc which I deleted by error