Fix bug caused by dereferencing incorrect map iterator