Add more legend parameters & refactor legend code