fixed a performance issue with element handling