Added Python 3 compatibility

I added some changes that will allow run script both on Pyhon3 and Python2.
Please review and accept.