Finished algorithm for determining category.