initial commit with modified code from David Moss