Fixed an exception by putting the if condition in {}.