more flexible way to determine start and end items