Fix a lot bugs