reorg, bug fixes, and unit test setup