Threaded version, poor performance