Improved JavaScript code.

I’m a n00b at JavaScript, so bear with me. :)