diff --git a/lib/modules/_Image_XPM.pmod b/lib/modules/_Image_XPM.pmod
index 82905f4f13519b8c3d904b4f83de11681e9fffe9..be9d62698c99c75eb8a16e0f3787fd20d3175e62 100644
--- a/lib/modules/_Image_XPM.pmod
+++ b/lib/modules/_Image_XPM.pmod
@@ -64,11 +64,13 @@ mapping _decode( string what, void|mapping opts )
     retopts->hot_y = values[5];
   }
   TD("Colors");
-  mixed colors = ([]);
   if(sizeof(data) < ncolors+2)
     error("Too few elements in array to decode color values\n");
-
-  colors = sort(data[1..ncolors]);
+  array colors;
+  if(cpp < 4)
+    colors = data[1..ncolors];
+  else
+    colors = sort(data[1..ncolors]);
   TD("Creating images");
   object i = Image.image( width, height );
   object a = Image.image( width, height,255,255,255 );