Rewriting js to ember, second step. Refactoring.