Lots of additional tests and fixes for bugs discovered.