This was split from issue #26. The PR associated with issue #26 contains an implementation from @bradhandy.