Some fixes and tests