refactoring and design fix