Rewrite the permissions checking methods to fix issue #77