A lot of compile fixes. Now it builds.
A lot of compile fixes. The structure and key write needs to be rethought.