I realize you did not introduce this, however, this logic could be simplified with an if-else statement.