Solution to second task + diagram