added invalid certificate treatment