refactored preprocessing to read the data left-to-right
refactored preprocessing to read sequential data from stream instead of memory block