Rationalize code layout
Add Python3 compatibility