Added write and close (untested)