lots of tests + a few bug fixes