improve js function