I think caching all the costume names is possible. We could work on the addCostume method itself to automatically prevent two costumes from having the same name.If every costume is added using the addCostume method then every costumes name is cached. Does this sound like a good idea to you?

I have not conducted any profiling. Creating a dictionary was an instinctive solution to the problem. It helped bring down additional searches that must be conducted for the costume names and then a search for the last number used. The automatically incrementing number after the name is similar to what most operating systems do when you try and create two files with the same name in the same directory.

I understand that having this random dictionary that is only useful for one function makes the codebase harder to understand. But conversely, if someone were trying to understand doScreenshot, they would find it much harder to comprehend all the nested for-loops going on.

I think your idea of caching all costume names is a good one. I will work on it if you think so too :)