Various changes merged from osx branch.