I don't think you need to doubly define (close) the function. That is, you should be able to remove line 9 and 31.