fix bugs and remove some useless cases