Clean-up of JavaScript code. Not yet tested.