Started refactoring Javascript code to accept arguments on instantiation