moved remove() call for aElem after all references