Modified to work with python 2.X.

Quick mod tested on python 2.7. Few minor changes/improvements.