I'm worried that ```stack``` might be undefined as you've not got an else clause from the if on 1013 e.g. if ```len(nd_indices) == 1```