many of these variables could use more verbose names. s is a good example but I also see that you used e, c, r, l, and i (i'll give you a pass on i). tup is also a bad one.