Reworked the closure function