These `@mut`'s are unfortunate (but they seem necessary with the current structure of the code).