The valid check (together with line 860) is slightly odd - why is (dsm_bind_val == 1) || (dsm_bind_val == 2) external, and why does the function not check / enforce it? I think it should be either inside the function, or be implemented externally.