Change stage at which elements are removed in order to avoid null reference segfault.