Refactored map_foreach* functions.

Removed a lot of duplicated code.
Added some documentation & comments.
Merge pull request #66 from piotrhalaczkiewicz/blocklist

Refactored map_foreach* functions.