Backported code from 0.11.x branch.

Signed-off-by: marco.minetti <marco.minetti@novetica.org>