updated to not be in a closure