Refactor code to fix a Force Close on rotation change.