Made changes to allow library to operate on any type of stream.