Modified to support an arbitrary read() method.