refactoring and debugging