fix many bugs