Refactored the MainActivity class.