manually merging https://github.com/civicrm/civicrm-core/pull/802