Fixed permission checking code.