partial refactoring of MainActivity