Fixed that elements are incorrectly destructed.
Refactored a little bit.