3.1 branch & compatibility fixes
Typo
Neaten code
Merged with 3.1