refactor some ply reader code