refactoring tightly coupled code