Optimized the split_at function slightly