made tabulate more algorithmically efficient