Integrated the two versions. Not quite done.