legend code commented and some deletions