Solution for second assignment (third week)