improve legends and save to file the rules