minor optimizations in recursive fin() function