Various patches from r1 to master