Why are you first doing contains and then doing a get? That doesn't make sense. Just do the get and check != null. this is a lot faster. I see that you do it more often. 

You could even merge the map.contains/map.get/map.remove into a map.remove. There is no need to 3 interactions? Computers are fast, but not if you let them do useless work.