Refactored table construction

Refactored the process of table construction to have more one-liners and extract logically different steps into separate functions. Also changed how table was being rendered because the previous method didn't work (was based on a misunderstanding of $.getJSON's return value). hopefully this fixes the latest rendering issue.