adding log and permissions check