replacing the other xapply with a native function to avoid requiring xapply