fix switch_to function