add support for readlines and fix problems with buffered reads