Backport/518 and 533

backport to 3.0.x
review by @dragos