corrected if implementation