[#2252] Backporting some changes from 2.1 thanks to @johnkary