Debugging, refactoring and adding a progress bar