New PR with fixes from comments in #769

Blew away my repository, necessitating a new pull request. #769 contains some comments on this.