Refactor, onClosed and onInitialized events