Speed up post-processing by using sets instead of lists