Fixed the code

Fixed small problems in the code. It works perfectly on python 2.7 now