Attempted improvement on #140.
Hopefully fixes #146 for good.