newer improved inline table sorting logic