Updated write(a_piece) method to keep track of downloaded pieces and blocks.