Cleanup of Python code for Python idioms + PEP8.

Also added comments, particularly where we introduce new Flask
ideas.