Optimise javascript