Enable Py 3 compat, refactor function

Make code compatible with Python 3. Refactor the `subscribe` function. For exact details, please see the commit messages and commit diffs.