support JWS encoding and fix many bugs