Replace while loop & add progress bar

Improved efficiency with for loop instead of while loop (can check with system.time, really helps for large matrices) and added a progress bar (default = FALSE) to alert user of progress