Improvements for ncols function