Adding protection against not list and len of list == 0