Added threads for better processing

- Added threads for better processing
- Fix handling output