Initial merge with 3.1.2

Managed merge trying to keep all features intact.