Corrected while loop logic to check for active scans to complete prior to performing maintenance actions.