Slavi's patch #2 from https://codereview.chromium.org/25478007