While posting I noticed a(nother?) mistake: I have if ... <= 1 folowed by elif ... == 1. 
I’ve corrected it now to if ... < 1 … elif ... == 1.
While posting I noticed a(nother?) mistake: I have if ... <= 1 folowed by elif ... == 1. 
I’ve corrected it now to if ... < 1 … elif ... == 1.