You could look up the avatarid from the inputted params and compare it to what is in the currentPersonProperties avatarId, if they are the same, null it out of the hashmap, then when you get further down, you have an updated hashmap that only includes the avatarids that you need the base64 image for.