Fix many small bugs