Fixes #363

Ready for review.