Some adjustments in the code.

https://www.drupal.org/node/2338561
https://www.drupal.org/node/2352673
https://www.drupal.org/node/2316687