Many changes from David's device and some minor changes.