Some fixes and improved tests