porting bug fixes from old opo