more tests and code cleanups