Simplifying nested if else statements and using guard clauses