Updated the end button functionality