hopefully working code minus the progress bar and delete function