diff --git a/textimage.module b/textimage.module
index 16b0e9f..b00082b 100644
--- a/textimage.module
+++ b/textimage.module
@@ -485,13 +485,7 @@ function textimage_image_from_preset($preset, $text, $additional_text = array())
       break;
 
     case 'ucwords':
-      $text = preg_replace_callback(
-        '/\s(\w+)\b/',
-        function ($m) {
-          return drupal_ucfirst($m[1]);
-        },
-        $text
-      );
+      $text = preg_replace_callback('/(\w+)/', '_textimage_ucwords', $text);
       break;
   }
 
@@ -563,6 +557,13 @@ function textimage_image_from_preset($preset, $text, $additional_text = array())
 }
 
 /**
+ * Callback for preg_replace_callback.
+ */
+function _textimage_ucwords($matches) {
+  return drupal_ucfirst($matches[1]);
+}
+
+/**
  * Stroke function.
  *
  * Adds a solid color stroke around an image with a transparent
