Clean javascript code using classes