Takeover of #289

Takes @gcelano's commit and applies it with some minor corrections.
Doing this out of convenience, less hassle to rebase the foreing remote
branch and needed to patch it anyway.

Closes #289