Added threading for better management and performance