btn[i] was passed directly, but because the function inside the lambda operates on local variables, the button's reference was not properly. So I have changed that and The partial function binds the current loop index to the callback function, ensuring that each button's click event is linked to the correct button and its state.