added from https://drupal.org/comment/8342697#comment-8342697 with some adjustments to alpha10