optimize read loop