reorganizing code, fixing test failures