correct some logical errors