Implemented proper back button functionality.