refactored to OO javascript