Restructured TS map computation

As close to final as it could get today.
Please introduce a global variable for these factors like `6` here.
This will make it easier to refactor your code into classes or functions and avoid inconsistencies.