Finally working ...though not technically thread safe.