created switch_processes function to move code out of main