Add more tests, improve exception handling, not quite py3k compat yet