code cleanups, refactoring