check mode in write function