A bunch of random bug fixes