Fixes bug with sprite name collision

Per recommendations from @am11 and @GProulx I changed the fix to look
for an exact match. The code is also a bit further split out for
clarity.