 	    SET bit = bit-1;
 	    SET mask = left_shift(cast(2 as bigint),bit);
 	    CASE 
-		WHEN (bit_and(mask,value)=0) THEN SET out = out || ''; 
+		WHEN (bit_and(mask,val)=0) THEN SET out = out || ''; 
 		ELSE SET out = out || (coalesce((select name from SecTarget where value=mask),'')||' ');
 	    END CASE;
 	END WHILE;
     RETURN out;
 END;
 
-CREATE FUNCTION fInsideMask(name varchar(40))
+CREATE FUNCTION fInsideMask(nme varchar(40))
 RETURNS smallint
 BEGIN
 RETURN ( SELECT cast(value as tinyInt)
 	FROM InsideMask
-	WHERE name = UPPER(name)
-	);
-END;
-
-CREATE FUNCTION fInsideMaskN(value smallint)
+	WHERE name = UPPER(nme)
+	);
+END;
+
+CREATE FUNCTION fInsideMaskN(val smallint)
 RETURNS varchar(1000)
 BEGIN
     DECLARE bit smallint, mask smallint, out varchar(2000);

		SET bit = bit-1;
		SET mask = left_shift(cast(2 as bigint),bit);
		CASE 
			WHEN (bit_and(mask,value)=0) THEN SET out = out || ''; 
			ELSE SET out = out || (coalesce((select name from PhotoStatus where value=mask),'')||' ');
	    	END CASE;
	END WHILE;

	    SET bit = bit-1;
	    SET mask = left_shift(cast(2 as bigint),bit);
	    CASE 
		WHEN (bit_and(mask,val)=0) THEN SET out = out || ''; 
		ELSE SET out = out || (coalesce((select name from ImageMask where value=mask),'')||' ');
	    END CASE;
	END WHILE;
    RETURN out;
END;

CREATE FUNCTION fTiMask(nme varchar(40))
RETURNS int
BEGIN
RETURN ( SELECT cast(value as int)
	FROM TiMask
	WHERE name = UPPER(nme)
	);
END;

CREATE FUNCTION fTiMaskN(val int)
RETURNS varchar(1000)
BEGIN
    DECLARE bit int, mask bigint, out varchar(2000);
