Update JavaScript - Function Optimization