fix nest function