Fix list index out of range