code cleanup, minor refactoring