diff --git a/src/w_wad.c b/src/w_wad.c
index c98ba09bd0d9d0d3836b59a18ca5d9634a7e8cb3..451130e604300545f0e10703f0604dc5b1c65bd2 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -1222,15 +1222,27 @@ lumpnum_t W_CheckNumForNameInBlock(const char *name, const char *blockstart, con
 
 // Used by Lua. Case sensitive lump checking, quickly...
 #include "fastcmp.h"
+static boolean
+FindLump (const char *name, int wad)
+{
+	INT32 j;
+	for (j = 0; j < wadfiles[wad]->numlumps; ++j)
+		if (fastcmp(wadfiles[wad]->lumpinfo[j].name,name))
+			return true;
+	return false;
+}
 UINT8 W_LumpExists(const char *name)
 {
-	INT32 i,j;
+	INT32 i;
+	if (wadfiles[WAD_MUSIC])
+	{
+		if (FindLump(name, WAD_MUSIC))
+			return true;
+	}
 	for (i = numwadfiles - 1; i >= 0; i--)
 	{
-		lumpinfo_t *lump_p = wadfiles[i]->lumpinfo;
-		for (j = 0; j < wadfiles[i]->numlumps; ++j, ++lump_p)
-			if (fastcmp(lump_p->name,name))
-				return true;
+		if (FindLump(name, i))
+			return true;
 	}
 	return false;
 }