Fixed mistakes in logic