fixed bug in dealing with last block of data