Reworking to allow a document object to be passed along to all event handlers.