Js refactor

Pulls the business logic out of the controller and into a utility class

Javadoc plz