Part 3 & 4: bug fixes