fixed some bugs, restore to working state