Refactor reader

refactored the reader, placed close in finally block