fix nested function errors