incorperating patch fixes from Dirk