Improved the back button functionality