Fix list index out of bounds