start refactor of the js code