added sorting function to tables