Updated the code to retain button state on change in orientation