Fix "IndexError: list index out of range" error