Added element references, rewrote everything to use them