begun refactoring code