v3.1.0 code cleanup and bug fixes
commit conflict cleanup