New PR with fixes from comments in #769

Blew away my repository, necessitating a new pull request. The older #769 can be closed but contains some discussion on this.