fix serveral bugs