Moved putIfAbsent() out of loop