Switched unnecessary lists to sets for speedup