Fix I{W,R,X}OTH check bug and refactoring