code cleanup, refactoring