Made a little progress, but can't get one thing.
Refactored to work with python 2.

Still works fine with python 3, but macs have 2 installed by default, I believe,
and I want it to work there.