Rewrite the way registers are done

Hopefully this improves performance.