Some tests, and a couple of bugs fixed