Important changes

Most of the code is re-organized and the event listners are now where
they belong - in the DOM ready section.