Optimized javascript perf