refactor to use io.Reader rather than string as the return type