refactor js code & update UI