generalize parsing and writing