Large rework, not currently compiling.