corrected hashmap iteration as per Katajakasa's suggestion