refactor JS to be more OO