fix a bunch of crashes