redesigned javascript table-making code