Fix bug that could occur if inventory size shrunk