added rescue block for invalid cert