Various fixes and a whole new set of tests