refacoring reader.c