prevent stepping out of bounds for prev and next