Rewriting js to ember, second step. Refactoring.

Rewriting js to ember, second step. Refactoring.