Working read/write loop