most of the differ code