refactor nested if-s