cleanup: remove dead code and miscellaneous cleanup/refactoring on overall structure