Sync with latest master and various fixes