Merge 1.3.1 changes to dev branch

master contains updates which break for opam-lib 1.1.1 but are necessary for the next version of opam-lib. This branch contains a few bugfixes and minor features that will be released as 1.3 without those breaking changes in master.