Fix loop in LSM manager to not run off the end.