Improved the performance for residual table creation