Repair some bugs