Put __version__ immediately after docstring

It’s a good idea to have it closer to the top of the file, so the version is obvious with little-or-no scrolling
Rearranged imports

* Determine Python 2 or 3 imports first
* All other imports grouped together
Move functions before classes
Move pseudo-private classes before others
Move all Exception classes last
Use 2 blank lines between classes
Merge pull request #10 from Zearin/code-tweaks

Minor code tweaks