Some cleanup. Remove accidental cycle in @data structure. Use
tools.logging more consistently. Add ability to write @data to a file.