Lots of bug fixing, and 4.7 merges