Fix bugs in extract cert