Adding codes to handle non-existing key or certificate