fix a bunch of bugs