You likely need to add debounce (or use firmware that has the inm module)
on the P1 input pins you are using since they have no filtering which means a 20 ns
glitch from EMI can be detected a a momentary state change.
EMI filtering the signals near P1 is also not a bad idea.