Fixed bug in the if check