Improve js code