Refactor js to oo