Minor js refactor
Converted logic to angular controller