Extend and fix many bugs in convert.