copied fix from master