attempted to make the code elegant using reference classes. seems too much trouble, for now. going back to functional code.