looks like vector is not needed, you could traverse map elements and detach at the same time