Solve the issue with closures by hijacking the serialize handler.