refractor template and js code