Fixed double calling onExit method.
Little refactor.
Merge pull request #6756 from zifter/FixTwiceCallingOnExit

Fix twice calling on exit