Starting rewrite to Angularjs