add closure function solution - the previous stuff needs fixing