change the if to be nested