More refactoring (still a lot left), fixed bug where everything went strange when an element got parented to another parent.