Fix some indexing issues, comply with PEP8