refactoring, code cleanup, logging