Fix a lot of bugs.