HowTo remove an arbitrary element and retrieve that item at the same time?