added writing functionality