refacto nested if for control statements