fixes #149

Rebased just before I started this branch today.