fix permission check

fixes #584