simpler version of fix from commit f70673f60ea11074a3763379eab936d72f451c24