Added array length checks for getting items from inventory slots