Refactor, cleaning, and testing of MainActivity