Refactor angularjs code
Refactor angular code and fix some bugs