Classes preserved in SVG output and a bunch of cleanup

#63 plus changes mentioned in line notes.