changed if condition to nested if condition

changed if to nested if. shortens the condition and makes the code more readable.