Partial fix for Issue #9; tests for new code.

Realised I hadn't yet created a pull request for this issue.