Fix crashes

This should fix some of the crashes @jdotpz has been seeing.