This is work in progress (may not even compile); will fix it on another machine).