reopen of #7

thanks to @briancurtin for his contributions.

these are rewritten commits to mirror his work from #7