refine js code