Merging in changes from #3594

Thanks to @toddejohnson for doing the actual work on this.