Fix mutability bugs