Fix many bugs