added a function for writing blocks of data