solved the problem for captured functions

FIXME: might be very inefficient