Port commits from dev branch

These commits seems safe for me but I'd be happy for review.

// cc @arikon