First bit much trickier than the second.