Adding in the solution by Cormac and me.