advanced code refactoring