Move cacert to function