Finally got something working in principle.