fixed indexing problem
updated to be more python3 compatible