Improved a JavaScript function.