Added check for empty list