take end into account