fix some logical errors