A lot of small fixes and test fixes