porting changes from @sya's testing back upstream