New PR, on a new branch, still fixing #111

I managed to screw up my previous branch in the process of rebasing it.

This branch has the same changes, in just two commits.

See comments on previous PR: #130