Converted the code to use new Python3 APIs

Python2 is pretty outdated so I converted cortex to use the Python3 APIs