Fixed error in logic