Third homework - improvements

Use sets instead of lists to avoid repetitions