applying a couple of fixes from master