generating a safer if and switch