Initial port of core code to Python3.