misc cleanup and refactoring