added progress bar and refactored some code