PR for #40

Not ready to merge, but I started the PR to get an easy view into the changes.