refactored oo javascript