Restructure so all DOM elements can be sorted