Backported commits by #pablasso (https://github.com/pablasso)