Attempt to fix a bunch of bugs