First round of bug fixes