Greatly improve performance by using lists instead of sets

almost everywhere