Add check for empty table before sorting on security