better special case to speed up recursive function