a bunch of bug fixes