refactored code to give the main panel control over the main data thread.