Fixed logical bug for checking permissions