added legend, various other changes