Note that you can use python -m cProfile main.py to do profiling.
removed some unneeded deepcopy calls and some old code that wasn't being used anymore.