Corrected if statement bug