Defensive programming for MainActivity