Refactor directory structure

split main.js into controller, factories and directives as far as possible.