replace if with when