Fix bugs in perm4 table and add more testcases