Fixes for python3. Also, there is an index out of bounds error.
Merge pull request #1 from justinvf/master

Makes this all work for python3