separated legend into own function