add docs, thread safe, cleanup