Merge from upstream

Merge latest changes from upstream including bug fixes, dry running and template support.