Backported new functionality to 0.9-dev branch