few newer changes copied from hamza