I taken from https://api.drupal.org/comment/2738#comment-2738