Fix `IndexError` thrown in `do_function`