significant code improvements to legends in particular