Added more handling for null references. Added more disposal for event handlers.