begin refactoring with angularjs