moved reader into function