Sundry bug fixes, tests now (mostly) passing.
All bar one test passes.
Merge pull request #96 from shans/fixTests

Fix tests