misc cleanup & refactoring