refactoring code into angular