fix some difficult bugs