Encapsulating tab switching into its own function. Adding function callbacks (before and after switching tabs)