Refactored mode hooks and simplified the exit process.