Test cleanup

Version of PR #116, refreshed against master.