Restructured TS map computation

As close to final as it could get today.
Can you please remove the `sorted` call here and instead manually sort these?
Having them sorted in the source code is also very useful for devs to quickly find things in long lists.