Code adjusted for Huw's data structure