I think it would make sense to have all this code inside a closure.