Fixed issue 1160 and also redirected from pull request 2947

I am creating another pull request because I messed up commits on my local machine. So here I create a new branch and update all the required files. I have made the code PEP8 compliant. (Used the Python PEP8 Auto format plugin on Sublime Text 2) Please do point out any discrepancies in this commit that you find.