The following code works, but, what is the proper way to interact with the CAPTCHA module, programmatically?

More info, if you're interested:
I have a plain HTML form that I'm trying to add a CAPTCHA element to via the CAPTCHA module. I have a custom module added to Drupal that is providing some code to give me the CAPTCHA element and check the answer.

I was initially using PHP Sessions for storing and checking solutions. This worked great with the Math type CAPTCHA, but now that I am trying to implement an image CAPTCHA, I am seeing there is a table that saves the solutions and is used to check the values.

<?php
function custom_forms_get_captcha($key)
{
   
module_load_include('inc', 'captcha');
   
drupal_add_js(drupal_get_path('module', 'captcha') . '/captcha.js');
   
$captchaSid                                       = _captcha_generate_captcha_session($key); // Calling a private function.
   
$captchaKey                                       = sha1( time() . ip_address() . mt_rand(1,1000) . mt_rand(1,1000));
   
$captchaInfo                                      = image_captcha_captcha('generate', 'Image', $captchaSid);
   
$captchaInfo['form']['captcha_response']['#name'] = 'captcha_response';
   
db_update('captcha_sessions')
      ->
fields(array('solution' => $captchaInfo['solution'], 'token' => $captchaKey))
      ->
condition('csid', $captchaSid)
      ->
execute();
   
$captchaEl = drupal_render($captchaInfo['form']);
   
$_SESSION["{$key}_{$captchaKey}"] = $captchaInfo['solution'];
    return array
        (
           
'info'     => $captchaInfo,
           
'elements' => $captchaEl,
           
'key'      => $captchaKey,
        );
}
function
custom_forms_check_captcha($formVals, $key)
{
   
$result = false;
   
$captchaSolution = $_SESSION[ "{$key}_{$formVals['dai_c']}" ];
    unset(
$_SESSION[ "{$key}_{$formVals['dai_c']}" ]);
    if (
$captchaSolution == trim($formVals['captcha_response']))
    {
       
$result = true;
    }
    else
    {
       
drupal_set_message(t('The code you provided did not match the image. Please try again.'), 'error');
    }
    return
$result;
}
?>