cleanup, formatting, minor refactoring