Backported commits from master 

Bug and stability as well as some build fixes and performance improvements are included.
This pull requests includes the following pull requests:

#1429, #1395, #1422, #1394, #1415, #1405, #1416, #1421, #1389, #1413, #1409, #1406, #1402, #1401, #1397, #1379, #1386, #1388

As well as some cherry-picks.