Fixed IndexError: list index out of range issue