Improved my email switching function