optimization code javascript