Final code cleaning.

Switched to jQuery for most of the event listeners.