Rewrite internal list length function.