VE-1299: Fix. I discussed it pretty extensively with Ed Sanders from WMF...

... and the solution endedup in upstream repo https://gerrit.wikimedia.org/r/#/c/144067/ - so this commit is just a merge of that solution.