cleanups and refactoring