Allow algorithm to be changed

Also rearranged structure so the element is at the root