refactoring code for design