replaces closures with functions