Refactor and add progress bar