fixed the if loop