Cleaning up table views into a reusable function