I guess this part could be extracted into a separate pull request to keep the diff a bit smaller. It might also be useful to use the same thing for the map code too. iirc there is some throttling code in there too.