initial optimisation of javascript

nt