created connect, write and read functions