Rewrote the code for adding rows in place