Various bugfixes and some changes for compatibility with v3.2.