Fixed issue with logical error in if else statement