Lots of little changes

legend stuff, testing, cleanup, etc.