Updated with latest fixes from master