[ticket/13018] Do not handle events in close function.

PHPBB3-13018
[ticket/13018] Clean up and fix some logic.

PHPBB3-13018