Some fixes and a few tests