Checkpoint

Code is currently broken. Roll back and branch from 8fc6815af6 if you need to use this as it was.