Refactor ui js

used Nate's code review notes to refactor into a more object oriented format.