better test code and a few other fixes