Fix serveral bugs