client: replace duplicate code with read_data()