Modified the if statement structure to be more logical