Added proper threading/communication.
Removed unused imports.