added a bunch of random bug fixes