avoiding nested if because couldn't make it work