Added permissions check for read and write privileges.