One helper function for all fragment switching