Refine javascript