refactor of angularjs code

- to make proper use of modules
- to take all functions out of the global scope