Unify python 2 and 3 codebases

Work in progress of #38 merge into master.