improve js code