fixed switching code