Move check functions to the module level.
Rename some variables.
Use 'six' module for Python 2/3 compatibility.