Cleaned up the JavaScript code a bit.