(refactor) transfers logic to directives and factories, cleans up contro...

...ller