Refactored the main activity