More changes for python3 and improved logging/debugging. This ~works.