moving part of heavy front-end logic to back-end, as it only require run once to create the data structure.