Javascript: Refactor Procedural to OO