Fixed bug in calculation of spans.