Issue 152

A rather big commit, most is just whitespace / doc / escaping fixes. The fourth commit should resolve the issue originally reported in #152. Could do with a second pair of eyes to check there aren't unwanted side effects though.