minor fixes, cleanups, refactoring