Contributed by Eric Badger via eyang (cherry picked from commit e8dc862d3856e9eaea124c625dade36f1dd53fe2)