Create JavaScript - Function Optimization