Serious rework. Don't expect this to run for now.