Refactored
Removed check connection as it was causing issues stalling threads