Several fixes

r? @metajack