port some fixes from master