Various minor fixes and some new tests