initial pass at actual implementation attempt. many TODOs remain.