A whole bunch of bug fixes