Improved the reset logic