aaron: added onBeforeClose