Use HashDict update/4 and separate into function