rewrite of JWT.encode for clarity