Added a check for empty lists.