Restructure so all DOM elements can by sorted