Added advanced question solution. Messy, but it works.