Fixes for python3. Also, there is an index out of bounds error.