Optimize javascript