Separate SQL and add progress bar