port fixes from master