Fix if perm bug, add tests
Merge branch 'release/2.2.1'