Adding check for certificate expiration. Changes from pull request #3