Fix permissions-related bugs