Removes unnecessary list using a generator instead