begin refactoring code