fix many small bugs