various fixes and tests