porting Martin's changes