optimize JS code