code cleanup & refactoring