cleanup, code fixes, tests