Merged in all recent 1.3 changes (should have made the changes in this branch first and then backported instead but oh well, whatever works...).