much simplified and mostly working revised data structure and methods