Fixed some bugs in permissions