initial code from Roth/Kandel