Corrected if with nested if bracketing and wrapping pop limit setting