WIP #1001662

Opening this PR so we can talk about the code. Comments are inline :)