refactor reader code