Rewrite based on 8.x-1.x branch.