optimize js code