fixes #162. Back porting with a cut and paste