public static Map countOccurrences(Map imagesTags) {

        if (PRINT == 1)
            System.out.println("Creating tagpool and counting occurrences...\n");

        Map tagpool = new HashMap();

        /* Iterate through the map */
        Iterator itMap = imagesTags.entrySet().iterator();

        while (itMap.hasNext()) {
            Map.Entry pairFromMap = (Map.Entry) itMap.next();

             /* Select the list of tags in the pair (ArrayList) */
            ArrayList tagList = (ArrayList) pairFromMap.getValue();

            /* Iterate through that list and add to the tagpool with value 0 (counts) */
            for (String s : (ArrayList<String>) tagList) {
                /* If it doesn't already include the tag... */
                if (!(tagpool.containsKey(s))) {

                    tagpool.put(s, 0);

                    /* For every tag count through imagesTags, find each list and look for the search-tag, is it there: +1 in alltags */
                    Iterator countTags = imagesTags.entrySet().iterator();

                    while (countTags.hasNext()) {
                        Map.Entry countPair = (Map.Entry) countTags.next();

                        /* Find list in element */
                        ArrayList<String> arrayTags = (ArrayList<String>) countPair.getValue();

                        /* Is search in there? */
                        if (arrayTags.contains(s)) {
                            /* increment value by one in ALLTAGS */
                            tagpool.put(s, (Integer) tagpool.get(s) + 1);
                        }
                    }
                }
            }
        }

        if (PRINT == 1)
            System.out.println("Created tagpool, counting successful.\n");

        return tagpool;
    }